package ec.atreasure.com.atreasureecandroid;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Toast;

import ec.atreasure.com.core.ui.AtreasureLoader;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

import java.util.WeakHashMap;

import ec.atreasure.com.core.app.Atreasure;
import ec.atreasure.com.core.fragments.AtreasureFragment;
import ec.atreasure.com.core.net.RestClient;
import ec.atreasure.com.core.net.RestCreator;
import ec.atreasure.com.core.net.callback.IError;
import ec.atreasure.com.core.net.callback.IFailure;
import ec.atreasure.com.core.net.callback.IRequest;
import ec.atreasure.com.core.net.callback.ISuccess;
import ec.atreasure.com.core.net.rx.RxRestClient;

/**
 * Description :
 * Created by wangjin on 2019/6/22.
 * Job number：
 * Phone ：18301070822
 * Email： 120182051@qq.com
 * Person in charge : 汪渝栋
 * Leader：
 */
public class MainFragment extends AtreasureFragment {

    @Override
    public Object setLayout() {
        return R.layout.fragment_main;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
//        RestClient.getRestClientBuilder()
//                .withUrl("")
//                .setLoader(getContext())
//                .withParams(new WeakHashMap())
//                .setErrorCallback(new IError() {
//                    @Override
//                    public void onError(int code, String msg) {
//                        Toast.makeText(Atreasure.getApplicationContext(), "IError", Toast.LENGTH_SHORT).show();
//                    }
//                })
//                .setFailureCallback(new IFailure() {
//                    @Override
//                    public void onFaild() {
//                        Toast.makeText(Atreasure.getApplicationContext(), "IFailure", Toast.LENGTH_SHORT).show();
//                    }
//                })
//                .setRequestCallback(new IRequest() {
//                    @Override
//                    public void onStartRequest() {
//                        Toast.makeText(Atreasure.getApplicationContext(), "onStartRequest", Toast.LENGTH_SHORT).show();
//                    }
//
//                    @Override
//                    public void onEndRequest() {
//                        Toast.makeText(Atreasure.getApplicationContext(), "onEndRequest", Toast.LENGTH_SHORT).show();
//                    }
//                })
//                .setSuccessCallback(new ISuccess() {
//                    @Override
//                    public void onSuccess(String response) {
////                        Toast.makeText(Atreasure.getApplicationContext(), response, Toast.LENGTH_SHORT).show();
//                    }
//                })
//                .build()
//                .get();

        RxRestClient.getRxRestClientBuilder()
                .withUrl("")
                .setLoader(getContext())
                .withParams(new WeakHashMap())
                .build()
                .get()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(String s) {
                        Toast.makeText(Atreasure.getApplicationContext(), s, Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {
                        AtreasureLoader.stopLoading();
                    }
                });
    }
}
